package com.wgchao.mdmp.controller;

import com.wgchao.mdmp.common.ResultCommon;
import com.wgchao.mdmp.common.aal.AalData;
import com.wgchao.mdmp.common.aal.IpMessage;
import com.wgchao.mdmp.mapstruct.dto.GrYlData;
import com.wgchao.mdmp.service.DataService;
import com.wgchao.mdmp.service.UpLoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @作者：wgchao
 * @时间：19:34 2019/11/3 0003
 * @用途：
 **/
@RestController
@RequestMapping("/mdmp/data")
@Api(tags = "医疗数据信息管理")
public class DataController {
    @Autowired
    private DataService dataService;
    @Autowired
    private UpLoadService upLoadService;

    @GetMapping("/search/{idcard}")
    @ApiOperation(value = "查询患者检测数据", notes = "设定检测时间段，获取的数据类型（xy、hx、tw、xl、xt、sao2 逗号分割）")
    public ResultCommon<GrYlData> searchData(@PathVariable String idcard,
                                                   @RequestParam(required = false) Date startTime,
                                                   @RequestParam(required = false) Date endTime,
                                                   @RequestParam(required = false) String types) throws Exception{
        return dataService.searchData(idcard, startTime, endTime, types);
    }

    @GetMapping("/aal/upload")
    @ApiOperation(value = "愛奧樂设备数据上传")
    public String aalUpload(String data,HttpServletRequest request) throws Exception{
        try {
            return upLoadService.aalUpload(data, request);
        } catch (Exception e) {
            e.printStackTrace();
            return "+IP"+IpMessage.getIpOf16(request)+IpMessage.getDateOf16(new Date())+"ER";
        }
    }
}
